<template>
  <div 
    class="featured-item" 
    @mouseenter="showHover = true" 
    @mouseleave="showHover = false"
  >
    <img :src="product.imageUrl" :alt="product.name" class="featured-img">
    <div class="item-info">
      <h3 class="item-title">{{ product.name }}</h3>
      <p class="item-desc">{{ product.description }}</p>
      <div class="item-footer">
        <div class="item-price">
          <span class="current-price">¥{{ product.price }}</span>
          <span class="original-price" v-if="product.originalPrice">¥{{ product.originalPrice }}</span>
        </div>
        <div class="item-rating">
          <el-rate 
            v-model="product.rating" 
            disabled 
            show-score 
            text-color="#ff9900" 
            score-template="{value}分"
          />
        </div>
      </div>
    </div>
    <div class="item-hover" v-show="showHover">
      <div class="hover-content">
        <el-button type="primary" round @click="$emit('view', product.id)">查看详情</el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

defineProps({
  product: {
    type: Object,
    required: true
  }
})

defineEmits(['view', 'add-cart'])

const showHover = ref(false)
</script>

<style lang="scss" scoped>
.featured-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
  transition: all 0.3s;
  height: 100%;

  &:hover {
    transform: translateY(-5px);
  }

  .featured-img {
    width: 100%;
    height: 240px;
    object-fit: cover;
    border-radius: 8px 8px 0 0;
  }

  .item-info {
    padding: 15px;

    .item-title {
      font-size: 16px;
      color: #333;
      margin-bottom: 8px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      height: 40px;
      line-height: 20px;
    }

    .item-desc {
      color: #666;
      font-size: 14px;
      margin: 8px 0;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      height: 40px;
      line-height: 20px;
    }

    .item-footer {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 10px;

      .item-price {
        .current-price {
          color: #ff4d4f;
          font-size: 20px;
          font-weight: bold;
          margin-right: 8px;
        }

        .original-price {
          color: #999;
          text-decoration: line-through;
          font-size: 14px;
        }
      }
    }
  }

  .item-hover {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;

    &:hover {
      opacity: 1;
    }

    .hover-content {
      display: flex;
      flex-direction: column;
      gap: 10px;
      
      .el-button {
        padding: 12px 24px;
      }
    }
  }
}
</style>
